package com.example.demo.service;

/**
 * Model层，调用数据库操作接口实现类方法完成操作
 */
import com.example.demo.bean.Student;
import com.example.demo.dao.StudentDao;
import com.example.demo.factory.StudentDaoFactory;

import java.util.Collections;
import java.util.Comparator;
import java.util.List;

public class StudentService {
    private StudentDao studentDao;

    public StudentService() {
        this.studentDao = StudentDaoFactory.getStudentDao();
    }
//    获取要求的条数的学生信息      start起始位置 line往后多少行
    public List<Student> getAllStudentService(int start,int line) {
        List<Student> students = studentDao.getPageStudent(start,line);
        students.sort((o1, o2) -> Integer.parseInt(o1.getSid()) - Integer.parseInt(o2.getSid()));
        return students;
    }
//    获取总的学生数
    public Long getStudentCountService() {
        return studentDao.getStudentCount();
    }
//    根据给定的Student对象添加学生信息，返回Long类型的影响条数
    public Long addStudentService(Student student) {
        return studentDao.addStudent(student);
    }
//    根据给定的Student对象修改学生信息
    public void setStudentService(Student student) {
        studentDao.setStudent(student);
    }
//    根据给定的学号数组删除学生信息
    public void delStudentService(String[] sids) {
        studentDao.delStudent(sids);
    }
//    根据给定的学号和姓名获取学生信息
    public List<Student> queStudentService(String sid,String sname) {
        return studentDao.queStudent(sid,sname);
    }
}
